/**
 * This file is a part of qloudgen-sec. 
 * You can redistribute qloudgen-sec and/or modify it under the terms of the Lesser GNU General Public License version 3. 
 * qloudgen-sec is distributed WITHOUT ANY WARRANTY. 
 *
 * See the Lesser GNU General Public License for more details at http://www.gnu.org/licenses/. 
 **/
package org.qloudgen.sec.cas.support.user.services;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import org.qloudgen.sec.cas.support.user.userdetail.UserDetailDao;

import javax.validation.constraints.NotNull;

/**
 * 
 */
public final class DefaultUserDetailManagerImpl implements UserDetailManager{

    private final Logger logger = LoggerFactory.getLogger(DefaultUserDetailManagerImpl.class);

    /** Instance of dao. */
    @NotNull
    private UserDetailDao userDetailDao;

    public DefaultUserDetailManagerImpl(final UserDetailDao userDetailDao) {
        this.userDetailDao = userDetailDao;
    }


    public synchronized UserDetail delete(final String id) {
        final UserDetail r = findUserDetailBy(id);
        if (r == null) {
            return null;
        }
        logger.debug("usersDetailManageImple delete userDetail: {}",r);
        this.userDetailDao.delete(r);
        logger.debug("usersDetailManageImple delete userDetail end: {}",r);
        return r;
    }

    public UserDetail findUserDetailBy(final String id) {
        UserDetail r = this.userDetailDao.findUserDetailById(id);

        try {
            return r == null ? null : r;
        } catch (final Exception e) {
            return r;
        }
    }


    public synchronized UserDetail save(final UserDetail userDetail) {
    	
        final UserDetail r = this.userDetailDao.save(userDetail);
        return r;
    }
    
    public List<UserDetail> getAllUserDetail() {
        return userDetailDao.load();
    }
    
    public List<UserDetail> getCanDeleteUserDetail() {
        return userDetailDao.loadCanDelete();
    }
    
    public UserDetail findUserDetailByName(String colName){
    	
    	  return userDetailDao.findUserDetailByName(colName);
    }
}

